import json
from pydoc import plain

from requests import Response

import config
import unittest
import requests
from api.batchImportOrderList import BatchImportOrderList
from parameterized import parameterized

from scripts.test01_login import BuildData


def BuildData():
    file = config.BASE_DIR + "/data/mobile_no.json"
    with open(file, encoding="utf-8") as f:
        receivefile = json.load(f)
        mobile_nos = receivefile.get("mobile_no")
    data = []
    for i in mobile_nos:
        data.append((i,))
    return data

datajson = BuildData()
print(datajson)


class TestImportOrder(unittest.TestCase):
    def setUp(self):
        self.session = requests.session()

    def tearDown(self):
        self.session.close()

    @parameterized.expand(BuildData())
    def test01_importOrder(self, memberPhone):
        # 商品id
        productIds = "90003254"
        params = {
            "service_name": "salesmng.OrderBackFacade.batchImportOrderList",
            "client_id": "6",
            "strategy": "dubbo",
            "timestamp": 1668676167038,
            "token": config.TOKEN_RESULT[0].get("token"),
            "param": {
                "backOrderList": [
                    {
                        "memberPhone": memberPhone,
                        "productIds": productIds,
                        "classIds": "123789",
                        "provinceId": 35738,
                        "cityId": 52230,
                        "countyId": 14269,
                        "contact": "张三",
                        "mobileNo": memberPhone,
                        "addressDetail": "开课啦",
                        "odType": 1,
                        "odBizType": 1,
                        "lookPlatformId": 1,
                        "importMemberDTO": {
                            "realName": "张三",
                            "grade": 7,
                            "schoolId": 132537,
                            "classes": 79,
                            "mathScore": 100,
                            "scienceScore": 100,
                            "schoolRank": 10
                        },
                        "areaId": 76061,
                        "checkStock": "true",
                        "classType": "7",

                    }
                ],
                "operator": "6PaxK0sx"
            }
        }
        importorder = BatchImportOrderList()
        responses = importorder.batchImportOrderList(self.session, params)
        config.prints(responses)
        print(f"响应信息：{responses.json()}")
        self.assertEqual("1000001", responses.json().get("code"))
        # self.assertEqual([], responses.json().get("data").get("resultList"))
